/**********************************************************************************************
Trigger Name: NMRUserOfficeUpdateTrg 
* Author: Accenture 
* Date: 14-March-2012  
* Requirement/Project Name: NMR 
* Purpose: Create User Office Map for NMR Sales                         
***********************************************************************************************/
trigger NMRUserOfficeUpdateTrg on User (before insert,after insert) {
    Set<Id> NMRUserRoles = new Set<Id>();
    //Set<String> NMROfficeCodes = new Set<String>();
    Map<string,List<User>> OfficeUserMap = new Map<string,List<User>>();
    Map<string,Sales_Office__c> OfficeMap = new Map<string,Sales_Office__c>();
    Set<Id> userId = new Set<Id>();
    List<User> userList = new List<User>();
     
    for (UserRole singlerole: [SELECT Id, Name FROM UserRole WHERE Name LIKE 'IR Sales%']) {
       NMRUserRoles.add(singlerole.Id);
    }
    for(User usr:Trigger.New){
       
                if(TRIGGER.ISAFTER){
                 userId.add(usr.Id);
                 }
                 if(TRIGGER.ISBEFORE){
                     if(usr.OOR_Hire_Date__c == NULL && NMRUserRoles.contains(usr.UserRoleId)){
                     usr.OOR_Hire_Date__c = Date.Today();
                 }
                 }
               
    }
    if(userId.size()>0){
    NMRUserSalesOffice.nmrUserinsert(userId,NMRUserRoles);
    }
  
}